package com.tyqx.hashchainbiz.controller.donate.cash;

import com.tyqx.hashchainbean.module.DonateCash;
import com.tyqx.hashchainbean.vo.DonateCashVO;
import com.tyqx.hashchainbean.vo.QueryParamVo;
import com.tyqx.hashchainbean.vo.QueryTimeParamVo;
import com.tyqx.hashchainbiz.service.DonateCashService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.Future;

@Api(description = "资金捐赠")
@RestController
@RequestMapping("/donateCash")
@CrossOrigin
@EnableAsync
public class DonateCashController {

    @Resource
    private DonateCashService donateCashService;

    @ApiOperation(value = "添加资金捐赠", httpMethod = "POST")
    @RequestMapping(value="/saveDonateCash", method = RequestMethod.POST)
    @ResponseBody
    public String saveDonateCash(@RequestBody DonateCashVO donateCashVO) throws Exception {

        String msg="";
        System.out.println("donateCashVO:");
        System.out.println(donateCashVO.getUserName());
        DonateCash donateCash=new DonateCash();
        donateCash.setUserName(donateCashVO.getUserName());
        donateCash.setDonateAmount(donateCashVO.getDonateAmount());
        donateCash.setDonatee(donateCashVO.getDonatee());
        donateCash.setDonateId(donateCashVO.getDonateId());
        donateCash.setDonateType(donateCashVO.getDonateType());
        donateCash.setDonateTime(donateCashVO.getDonateTime());
        Future<String> future= donateCashService.donateCash(donateCash);
        /*if(trackDonateService.donateCash(donateCash).isDone()){
            msg="资金捐赠成功";
        }else{
            msg="资金捐赠失败";
        }*/
        //trackDonateService.donateCash(donateCash);
        msg="资金捐赠成功";
        return msg;
    }

    @ApiOperation(value = "通过资金捐赠id查询数据", httpMethod = "POST")
    @RequestMapping(value="/getDonateCashById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<DonateCash> getDonateCashById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return donateCashService.getDonateCashById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getDonateCashByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<DonateCash> getDonateCashByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return donateCashService.getDonateCashByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
